/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.anny.wxuser.service;

import java.util.List;

import com.jeeplus.modules.anny.shop.entity.AnnyShop;
import com.jeeplus.modules.anny.shop.mapper.AnnyShopMapper;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.anny.wxuser.entity.AnnyWxUser;
import com.jeeplus.modules.anny.wxuser.mapper.AnnyWxUserMapper;

/**
 * 微信对应用户Service
 *
 * @author linzx
 * @version 2018-10-19
 */
@Service
@Transactional(readOnly = true)
public class AnnyWxUserService extends CrudService<AnnyWxUserMapper, AnnyWxUser> {
    @Autowired
    private AnnyWxUserMapper annyWxUserMapper;
    @Autowired
    private AnnyShopMapper annyShopMapper;
    @Autowired
    private UserMapper userMapper;

    public AnnyWxUser get(String id) {
        return super.get(id);
    }

    public List<AnnyWxUser> findList(AnnyWxUser annyWxUser) {
        return super.findList(annyWxUser);
    }

    public Page<AnnyWxUser> findPage(Page<AnnyWxUser> page, AnnyWxUser annyWxUser) {
        return super.findPage(page, annyWxUser);
    }

    @Transactional(readOnly = false)
    public void save(AnnyWxUser annyWxUser) {
        super.save(annyWxUser);
    }

    @Transactional(readOnly = false)
    public void delete(AnnyWxUser annyWxUser) {
        super.delete(annyWxUser);
    }


    /**
     * 判断用户是否存在
     *
     * @param openid
     * @return
     */
    public List<AnnyWxUser> selectOpenID(String openid) {
        return annyWxUserMapper.selectOpenID(openid);
    }

    /**
     * 设置用户昵称，获取电话号码赋值用户昵称
     */
    @Transactional(readOnly = false)
    public void setNickName(String wxOpenId) {
        List<AnnyWxUser> annyWxUser = annyWxUserMapper.selectOpenID(wxOpenId);
        AnnyWxUser wxUser = (AnnyWxUser) annyWxUser;
        String userID = wxUser.getUserID();
        User user = userMapper.get(userID);
        String photo = user.getPhoto();
        wxUser.setNickName(photo);
    }

    public List<AnnyWxUser> wxUserALl() {

        return annyWxUserMapper.wxUserALl();
    }

    /**
     * 获取所有商家
     * @return
     */
    public List<AnnyShop> selectShopLocation(){
       List<AnnyShop> shop= annyShopMapper.selectShopLocation();
       return shop;
    }
}